<?php
namespace app\admin\controller;

use think\Db;
class Theme extends Base
{
    public function themes()
    {
        if(request()->isAjax()){
            $theme = input("identi");
            $type = input("type");
            $saveTheme = Db::name("system")->where("config","themes")->update([ $type => $theme]);
            if($saveTheme){
                return json(["code" => 1, "msg" => "应用主题成功"]);
            }
            return json(["code" => 0, "msg" => "应用主题失败"]);
        }else{
            $themesPath = ROOT_PATH ."public".DS ."themes";
            $fileList = scandir($themesPath);
            $themeList = [];
            foreach($fileList as $item){
                if($item == "." || $item == ".."){
                    continue;
                }
                if(!is_dir($themesPath .DS .$item)){
                    continue;
                }
                $infoPath = $themesPath .DS .$item .DS ."info.php";
                if(file_exists($infoPath)){
                    include($infoPath );
                    $info["identi"] = $item;
                    $themeList[] = $info;
                }
            }
            return view('/themes',["themeList" => $themeList]);
        }
    }
}